﻿using System.Collections.Generic;
using UnityEngine;

public class EnemyChaseState : IEnemyState
{
    public EnemyChaseState(EnemyFSMSystem fsm, ICharacter character) : base(fsm, character)
    {
    }

    private Vector3 mTargetPos;

    public override void DoBeforeEntering()
    {
        mTargetPos = GameFacade.Instance.GetEnemyTargetPos();
    }

    public override void Reasoning(List<ICharacter> targets)
    {
        if (targets != null && targets.Count > 0)
        {
            float distance = Vector3.Distance(mCharacter.Position, targets[0].Position);
            if (distance <= mCharacter.AtkRange)
            {
                mFSM.PerformTransition(EnemyTransition.CanAttack);
            }
        }
    }

    public override void Actioning(List<ICharacter> targets)
    {
        if (targets != null && targets.Count > 0)
        {
            mCharacter.MoveTo(targets[0].Position);
        }
        else
        {
            mCharacter.MoveTo(mTargetPos);
        }
    }
}